package com.example.supplychainbackend.entity.purchase;

import com.example.supplychainbackend.tool.DateTimeUtils;
import jakarta.persistence.*;
import lombok.*;

import java.util.concurrent.atomic.AtomicInteger;

@Entity
@Table(name = "purchase_contract")
@Data
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PurchaseContractEntity {
    @Id
    private String contractNo;

    private String contractType;
    private String supplierCode;
    private String company;
    private String supplierName;
    private Integer orderType;
    private Float taxExcludedAmount;
    private Float totalTax;
    private Float contractAmount;
    private String creator;
    private String createDate;
    private String lastApprovalTime;
    private String status;

    @Transient
    private static final AtomicInteger counter = new AtomicInteger(1);

    @PrePersist
    public void generateId() {
        if (contractNo == null || contractNo.equals("")) {
            contractNo = String.format("%s%s%04d",
                    "PRC", DateTimeUtils.getCurrentDateForID(), counter.getAndIncrement());
        }
    }
}
